package org.ihelpuoo.weboo.action.http;

import org.apache.log4j.Logger;
import org.ihelpuoo.lang.ExceptionUtils;
import org.ihelpuoo.weboo.module.ActionContext;

public class ForwardAction implements Action
{
	private static Logger	log	= Logger.getLogger(ForwardAction.class);

	public void execute(ActionContext context)
	{
		boolean redirect = context.properties().getBoolean("redirect");
		try
		{
			String fwd = this.doForward(context);
			if (null == fwd)
				fwd = context.getForwardName();
			if (null == fwd)
				fwd = context.getActionConfig().getPropertyValue("dest");
			context.forward(fwd,redirect);
		}
		catch (Exception e)
		{
			try
			{
				context.forward(context.properties().getString("dest.error"),false);
			}
			catch (Exception e1)
			{
				try
				{
					context.getResponse().getWriter().write(ExceptionUtils.dump(e));
				}
				catch (Exception e2)
				{
					log.warn(ExceptionUtils.dump(e));
				}
			}
		}
	}

	protected String doForward(ActionContext context) throws Exception
	{
		return null;
	}

}
